#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>

#include <QtGui/QApplication>
#include <QtGui/QMessageBox>

#include <qdeclarative.h>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeContext>


#include <QDebug>

#include "daomanager.h"
#include "specificsearch.h"
#include "widgetchart.h"

// Lock S60 orientation
#ifdef Q_OS_SYMBIAN
#include <eikenv.h>
#include <eikappui.h>
#include <aknenv.h>
#include <aknappui.h>
#endif

int main(int argc, char *argv[])
{
    QApplication application(argc, argv);

    qmlRegisterType<MoneyCategory>("Entity", 1, 0, "MoneyCategory");
    qmlRegisterType<Money>("Entity", 1, 0, "Money");
    qmlRegisterType<MoneyGoal>("Entity", 1, 0, "MoneyGoal");
    qmlRegisterType<SpecificSearch>("Entity", 1, 0, "SpecificSearch");
    qmlRegisterType<WidgetChart>("Charts", 1, 0, "WidgetChart");

    const QString mainQmlApp = QLatin1String("MoneyManager.qml");
    QDeclarativeView view;

    qDebug() << view.rootContext()->baseUrl();
    view.rootContext()->setBaseUrl(QUrl("common"));
    view.rootContext()->setContextProperty("daoManager", new DaoManager);

    QObject::connect(view.engine(), SIGNAL(quit()), qApp, SLOT(quit()));

    view.setSource(QUrl::fromLocalFile(QApplication::applicationDirPath()
                        + QDir::separator() + mainQmlApp));
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);

//    // Lock S60 orientation
#ifdef Q_OS_SYMBIAN
    CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
    TRAPD(error,
    if (appUi) {
        appUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
    }
    );
#endif

#if defined(Q_OS_SYMBIAN)
    view.showFullScreen();
#else // Q_OS_SYMBIAN
    view.setGeometry(QRect(100, 100, 640, 360));
    view.show();
#endif // Q_OS_SYMBIAN
    return application.exec();
}

